home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / lfs / lfsCacheBackend.c < prev    next >
C/C++ Source or Header  |  1990-10-19  |  5KB  |  211 lines

  1. /* 
  2.  * lfsCacheBackend.c --
  3.  *
  4.  *    Routines for file cache backend of an LFS file system.
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/lfs/RCS/lfsCacheBackend.c,v 1.1 90/10/19 16:05:03 mendel Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <sprite.h>
  21. #include <lfsInt.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25. static Fscache_BackendRoutines  lfsBackendRoutines = {
  26.         Fsdm_BlockAllocate,
  27.         Fsdm_FileTrunc,
  28.         Fsdm_FileBlockRead,
  29.         Fsdm_FileBlockWrite,
  30.         Lfs_ReallocBlock,
  31.         Lfs_StartWriteBack,
  32.  
  33. };
  34.  
  35. #define    LOCKPTR    &lfsPtr->cacheBackendLock
  36.  
  37.  
  38. /*
  39.  *----------------------------------------------------------------------
  40.  *
  41.  * LfsCacheBackendInit --
  42.  *
  43.  *    Initialized the cache backend of an LFS file system.
  44.  *
  45.  * Results:
  46.  *    None.
  47.  *
  48.  * Side effects:
  49.  *    None.
  50.  *
  51.  *----------------------------------------------------------------------
  52.  */
  53.  
  54. Fscache_Backend *
  55. LfsCacheBackendInit(lfsPtr)
  56.     Lfs        *lfsPtr;    /* LFS file system structure. */
  57. {
  58.     Sync_LockInitDynamic(&(lfsPtr->cacheBackendLock), "LfscacheBackendLock");
  59.     lfsPtr->writeBackActive = FALSE;
  60.     lfsPtr->writeBackMoreWork = FALSE;
  61.     lfsPtr->shutDownActive = FALSE;
  62.     lfsPtr->cacheBlocksReserved = 0;  /* Filled in at end of attach. */
  63.     return Fscache_RegisterBackend(&lfsBackendRoutines,(ClientData) lfsPtr, 0);
  64. }
  65.  
  66.  
  67. /*
  68.  *----------------------------------------------------------------------
  69.  *
  70.  * Lfs_StartWriteBack --
  71.  *
  72.  *    Request that the segment manager start the segment write sequence
  73.  *    for the specified file system.
  74.  *
  75.  * Results:
  76.  *    True is a backend backend was started.
  77.  *
  78.  * Side effects:
  79.  *    A write back process may be started.
  80.  *
  81.  *----------------------------------------------------------------------
  82.  */
  83.  
  84. Boolean
  85. Lfs_StartWriteBack(backendPtr)
  86.     Fscache_Backend    *backendPtr; /* LFS file system backend. */
  87. {
  88.     Lfs     *lfsPtr;    /* File system with data to write. */
  89.  
  90.     lfsPtr = (Lfs *) (backendPtr->clientData);
  91.  
  92.     LOCK_MONITOR;
  93.     LFS_STATS_INC(lfsPtr->stats.backend.startRequests);
  94.     if (lfsPtr->writeBackActive) {
  95.     LFS_STATS_INC(lfsPtr->stats.backend.alreadyActive);
  96.     /*
  97.      * If we already have a SegmentWriteProcess active just set
  98.      * a bit indicating more work may be present.  This elimates the
  99.      * race been being notified for work while a WriteBack process
  100.      * is terminating.
  101.      */
  102.     lfsPtr->writeBackMoreWork = TRUE;
  103.     UNLOCK_MONITOR;
  104.     return FALSE;
  105.     }
  106.     lfsPtr->writeBackActive = TRUE;
  107.     Proc_CallFunc(LfsSegmentWriteProc, (ClientData) lfsPtr, 0);
  108.     UNLOCK_MONITOR;
  109.     return TRUE;
  110.  
  111. }
  112.  
  113. /*
  114.  *----------------------------------------------------------------------
  115.  *
  116.  * LfsStopWriteBack --
  117.  *
  118.  *    Stop cache writeback processing on the specified file system. 
  119.  *    This routine is called at file system shutdown time to wait
  120.  *    for the writeback processes to exit.
  121.  *
  122.  * Results:
  123.  *    None.
  124.  *
  125.  * Side effects:
  126.  *    None.
  127.  *
  128.  *----------------------------------------------------------------------
  129.  */
  130.  
  131. void
  132. LfsStopWriteBack(lfsPtr)
  133.     Lfs    *lfsPtr; /* File system to stop writeback for. */
  134. {
  135.     Time time;
  136.  
  137.     LOCK_MONITOR;
  138.     lfsPtr->shutDownActive = TRUE;
  139.     while (lfsPtr->writeBackActive) {
  140.     time.seconds = 1;
  141.     time.microseconds = 0;
  142.     Sync_WaitTime(time);
  143.     }
  144.     UNLOCK_MONITOR;
  145. }
  146.  
  147.  
  148. /*
  149.  *----------------------------------------------------------------------
  150.  *
  151.  * LfsMoreToWriteBack --
  152.  *
  153.  *    Check to see if we got another request for writeback.. 
  154.  *
  155.  * Results:
  156.  *    TRUE if we got request. FALSE otherwise.
  157.  *
  158.  * Side effects:
  159.  *    None.
  160.  *
  161.  *----------------------------------------------------------------------
  162.  */
  163.  
  164. Boolean
  165. LfsMoreToWriteBack(lfsPtr)
  166.     Lfs    *lfsPtr; /* File system to check for more work. */
  167. {
  168.  
  169.     LOCK_MONITOR;
  170.     if (lfsPtr->shutDownActive) {
  171.     lfsPtr->writeBackMoreWork = FALSE;
  172.     }
  173.     if (lfsPtr->writeBackMoreWork) {
  174.     lfsPtr->writeBackMoreWork = FALSE;
  175.     UNLOCK_MONITOR;
  176.     return TRUE;
  177.     }
  178.     lfsPtr->writeBackActive = FALSE;
  179.     lfsPtr->writeBackMoreWork = FALSE;
  180.     UNLOCK_MONITOR;
  181.     FscacheBackendIdle(lfsPtr->domainPtr->backendPtr);
  182.     return FALSE;
  183. }
  184.  
  185.  
  186. /*
  187.  *----------------------------------------------------------------------
  188.  *
  189.  * Lfs_ReallocBlock --
  190.  *
  191.  *    Allocate a new block on disk to replace the given block.  This is
  192.  *    intended to be used by the cache when it can't write out a block
  193.  *    because of a disk error.
  194.  *
  195.  * Results:
  196.  *     None
  197.  *
  198.  * Side effects:
  199.  *
  200.  *----------------------------------------------------------------------
  201.  */
  202. /*ARGSUSED*/
  203. void
  204. Lfs_ReallocBlock(data, callInfoPtr)
  205.     ClientData        data;            /* Block to move */
  206.     Proc_CallInfo    *callInfoPtr;    
  207. {
  208.     panic("Lfs_ReallocBlock called.\n");
  209. }
  210.  
  211.